package com.wfy.service;

import com.wfy.mapper.SpecGroupMapper;
import com.wfy.mapper.SpecParamMapper;
import com.wfy.pojo.SpecGroup;
import com.wfy.pojo.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Title: SpecService
 * @Package com.wfy.service
 * @Author 王飞遥
 * @Date 2022/8/22 19:52
 */
@Service
public class SpecService {
    @Autowired
    SpecGroupMapper specGroupMapper;
    public List<SpecGroup> queryGroupByCid(Long cid) {
        SpecGroup specGroup = new SpecGroup();
        specGroup.setCid(cid);
        return specGroupMapper.select(specGroup);
    }
    public void saveGroup(SpecGroup specGroup) {
        specGroupMapper.insertSelective(specGroup);
    }
    @Autowired
    SpecParamMapper specParamMapper;

    public void saveParam(SpecParam specParam) {
//        if(specParam.getId()==null){
            specParamMapper.insertSelective(specParam);
//        }else{
//            specParamMapper.updateByPrimaryKey(specParam);
//        }
    }

    public void updateParam(SpecParam specParam) {
        specParamMapper.updateByPrimaryKey(specParam);
    }

    public int delectParam(Long id) {
        return specParamMapper.deleteByPrimaryKey(id);
    }

    public List<SpecParam> queryParams(Long gid, Long cid, Boolean generic, Boolean searching) {
        SpecParam specParam = new SpecParam();
        specParam.setGroupId(gid);
        specParam.setCid(cid);
        specParam.setGeneric(generic);
        specParam.setSearching(searching);
        return specParamMapper.select(specParam);
    }
}
